/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PembayaranReportPanel.java
 *
 * Created on Nov 4, 2014, 3:19:43 PM
 */
package com.ivanbiz.ui;

import com.ivanbiz.dao.PembayaranDAO;
import com.ivanbiz.dao.impl.PembayaranDAOImpl;
import com.ivanbiz.model.Pembayaran;
import com.ivanbiz.service.ServiceHelper;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author IW20149X
 */
public class PembayaranReportPanel extends javax.swing.JPanel {

    List<Pembayaran> listPembayaran;

    /**
     * Creates new form PembayaranReportPanel
     */
    public PembayaranReportPanel() {
        initComponents();
        refresh();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablePembayaran = new javax.swing.JTable();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Report Pembayaran");

        tablePembayaran.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tablePembayaran);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 893, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tablePembayaran;
    // End of variables declaration//GEN-END:variables

    private void refresh() {
        try {
            PembayaranDAO pembayaranDAO = new PembayaranDAOImpl();
            listPembayaran = pembayaranDAO.getAll(Pembayaran.class);
            updateTablePembayaran();
        } catch (Exception ex) {
            Logger.getLogger(PembayaranReportPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void updateTablePembayaran() {
        String[] judul = {"No", "Tanggal Bayar", "Transaksi Reference", "Kos dan Kamar", "Krediture", "Jumlah", "Deskripsi"};
        Object[][] isi = new Object[listPembayaran.size()][7];
        int x = 0;
        int no = 0;
        for (Pembayaran pembayaran : listPembayaran) {
            no += 1;
            isi[x][0] = no;
            isi[x][1] = pembayaran.getDateCreated();
            isi[x][2] = pembayaran.getTransactionReference();
            isi[x][3] = pembayaran.getDebitBankAccount().getNoGL();
            isi[x][4] = pembayaran.getKreditBankAccount().getNameGL() + " A/C No " + pembayaran.getKreditBankAccount().getNoGL();
            isi[x][5] = pembayaran.getJumlah();
            isi[x][6] = pembayaran.getDeskripsi();
            x++;
        }
        new ServiceHelper().setAutoRize(isi, judul, tablePembayaran);
    }
}
